﻿using System.ComponentModel.DataAnnotations;

namespace Mabalacat.CPS.DataAccess.DataObjects
{
    public class EntityBase<TKey>       
    {

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        [Key]
        public TKey Id { get; set; }

        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>\
        /// <returns><c>true</c> if the <paramref name="obj"/> is equal to the current instance.</returns>
        public override bool Equals(object obj)
        {
            var value = obj as EntityBase<TKey>;
            return value != null && Id.Equals(value.Id);
        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        /// <summary>
        /// Creates a shallow copy of the current ModelObject<TKey> (does not clone reference fields; the reference values are shared between instances).
        /// </summary>
        /// <returns>A shallow copy of the instance.</returns>
        public virtual EntityBase<TKey> Clone()
        {
            return (EntityBase<TKey>)MemberwiseClone();
        }
    }
}
